package com.ruoyi.system.dao;

import com.ruoyi.common.core.domain.entity.SysAttachment;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.mapper.SysAttachmentMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * 附件Dao层
 * 
 * @author ruoyi
 * @date 2025-08-02
 */
@Repository
public class SysAttachmentDao
{
    @Autowired
    private SysAttachmentMapper sysAttachmentMapper;

    /**
     * 查询附件
     * 
     * @param id 附件主键
     * @return 附件
     */
    public SysAttachment selectById(String id)
    {
        return sysAttachmentMapper.selectById(id);
    }

    /**
     * 查询附件列表
     * 
     * @param sysAttachment 附件
     * @return 附件
     * @throws Exception
     */
    public List<Map<String, Object>> queryList(Map<String, Object> param) throws Exception
    {
        List<Map<String, Object>> list = sysAttachmentMapper.queryList(param);
        //BeanUtils.caseFormat(list); 在Mybatis拦截器插件中统一处理
		return list;
    }
    
    /**
     * 查询附件列表
     * 
     * @param sysAttachment 附件
     * @return 附件
     */
    public List<SysAttachment> selectList(SysAttachment sysAttachment)
    {
        return sysAttachmentMapper.selectList(sysAttachment);
    }

    /**
     * 新增附件
     * 
     * @param sysAttachment 附件
     * @return 结果
     */
    public int insert(SysAttachment sysAttachment)
    {
        if(StringUtils.isBlank(sysAttachment.getId())){
            sysAttachment.setId(UUID.randomUUID().toString());
        }
        if(sysAttachment.getCreateTime() == null){{
            sysAttachment.setCreateTime(DateUtils.getNowDate());
        }}
        sysAttachment.setStatus("0");
        return sysAttachmentMapper.insert(sysAttachment);
    }

    /**
     * 修改附件
     * 
     * @param sysAttachment 附件
     * @return 结果
     */
    public int update(SysAttachment sysAttachment)
    {
        if(sysAttachment.getUpdateTime() == null){{
            sysAttachment.setUpdateTime(DateUtils.getNowDate());
        }}
        return sysAttachmentMapper.update(sysAttachment);
    }

    /**
     * 批量删除附件
     * 
     * @param ids 需要删除的附件主键
     * @return 结果
     */
    public int deleteByIds(String[] ids)
    {
        return sysAttachmentMapper.deleteByIds(ids);
    }

    /**
     * 删除附件信息
     * 
     * @param id 附件主键
     * @return 结果
     */
    public int deleteById(String id)
    {
        return sysAttachmentMapper.deleteById(id);
    }
}
